﻿
@using IOA.MES.DataAccess.Enum
@{
    ViewBag.Title = "组件检索";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}
@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <form class="layui-form layui-card-header layuiadmin-card-header-auto" method="post" action="/Report/ExportComponents">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.OrderNo">订单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtOrderNo" name="orderNo" value="@ViewBag.OrderNo" @(!string.IsNullOrWhiteSpace(ViewBag.OrderNo) ? " disabled " : "") autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkorderNo">工单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtWorkOrderNo" name="workOrderNo" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CabinetNo">柜号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtCabinetNo" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.PackNo">箱号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtPackNo" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.BarCode">组件条码：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtBarCode" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button btntype="0" class="layui-btn layui-btn-warm layuiadmin-btn-list btnBatchSearch" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>批量组件查询
                        </button>
                        <button btntype="1" class="layui-btn layui-btn-warm layuiadmin-btn-list btnBatchSearch" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>批量包查询
                        </button>
                        <button btntype="2" class="layui-btn layui-btn-warm layuiadmin-btn-list btnBatchSearch" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>批量柜查询
                        </button>
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" lay-submit lay-filter="submit">
                            <i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>
                        </button>
                        <input type="hidden" id="hidBarCodes" name="barCode" value="" />
                        <input type="hidden" id="hidPackNos" name="packNo" value="" />
                        <input type="hidden" id="hidCabinetNos" name="cabinetNo" value="" />
                    </div>
                </div>
            </form>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form;

                var options = {
                    elem: '#table'
                    , url: '/Report/QueryComponents'
                    , method: "post"
                    , where: { orderNo: "", workOrderNo: "", cabinetNo: "", packNo: "", barCode: "" }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', type: "numbers", width: 60, fixed: "left" }
                        , { field: 'BarCode', title: '组件条码', minWidth: 200, fixed: "left" }
                        , { field: 'OrderNo', title: '订单号', minWidth: 150 }
                        , { field: 'WorkOrderNo', title: '工单号', minWidth: 200 }
                        , { field: 'CustomerCode', title: '客户代码', minWidth: 100 }
                        , { field: 'CustomerName', title: '客户名称', minWidth: 200 }
                        , { field: 'ProductCode', title: '成品料号', minWidth: 150 }
                        , { field: 'ProductName', title: '成品名称', minWidth: 250 }
                        , { field: 'WorkshopName', title: '生产车间', minWidth: 150 }
                        , { field: 'LineName', title: '流水线', minWidth: 150 }
                        , { field: 'CNLastSite', title: '最后站点', minWidth: 150 }
                        , { field: 'DistributeTimeStr', title: '分片时间', minWidth: 150 }
                        , { field: 'WeldingTimeStr', title: '焊接时间', minWidth: 150 }
                        , { field: 'WeldingDuty', title: '焊接班次', minWidth: 100 }
                        , { field: 'WeldingMachine', title: '焊接站点', minWidth: 100 }
                        , { field: 'WeldingUser', title: '焊接账号', minWidth: 100 }
                        , { field: 'LaminatedTimeStr', title: '叠层时间', minWidth: 150 }
                        , { field: 'LaminatedDuty', title: '叠层班次', minWidth: 100 }
                        , { field: 'LaminatedMachine', title: '叠层站点', minWidth: 100 }
                        , { field: 'LaminatedUser', title: '叠层账号', minWidth: 100 }
                        , { field: 'EL1TimeStr', title: 'EL1时间', minWidth: 150 }
                        , { field: 'EL1Duty', title: 'EL1班次', minWidth: 100 }
                        , { field: 'EL1Machine', title: 'EL1站点', minWidth: 100 }
                        , { field: 'EL1User', title: 'EL1账号', minWidth: 100 }
                        , { field: 'TopTimeStr', title: '层压时间', minWidth: 150 }
                        , { field: 'TopDuty', title: '层压班次', minWidth: 100 }
                        , { field: 'TopMachine', title: '层压站点', minWidth: 100 }
                        , { field: 'TopPosition', title: '层压位置', minWidth: 100 }
                        , { field: 'TopUser', title: '层压账号', minWidth: 100 }
                        , { field: 'NQCTimeStr', title: 'NQC时间', minWidth: 150 }
                        , { field: 'NQCDuty', title: 'NQC班次', minWidth: 100 }
                        , { field: 'NQCMachine', title: 'NQC站点', minWidth: 100 }
                        , { field: 'NQCUser', title: 'NQC账号', minWidth: 100 }
                        , { field: 'FramingTimeStr', title: '装框时间', minWidth: 150 }
                        , { field: 'FramingDuty', title: '装框班次', minWidth: 100 }
                        , { field: 'FramingMachine', title: '装框站点', minWidth: 100 }
                        , { field: 'FramingUser', title: '装框账号', minWidth: 100 }
                        , { field: 'CleanTimeStr', title: '清洗时间', minWidth: 150 }
                        , { field: 'CleanDuty', title: '清洗班次', minWidth: 100 }
                        , { field: 'CleanMachine', title: '清洗站点', minWidth: 100 }
                        , { field: 'CleanUser', title: '清洗账号', minWidth: 100 }
                        , { field: 'IVTestTimeStr', title: 'IV时间', minWidth: 150 }
                        , { field: 'IVTestDuty', title: 'IV班次', minWidth: 100 }
                        , { field: 'IVTestMachine', title: 'IV站点', minWidth: 100 }
                        , { field: 'IVTestUser', title: 'IV测试账号', minWidth: 100 }
                        , { field: 'InsulatedResistanceTimeStr', title: '绝缘耐压时间', minWidth: 150 }
                        , { field: 'InsulatedResistanceDuty', title: '绝缘耐压班次', minWidth: 100 }
                        , { field: 'InsulatedResistanceMachine', title: '绝缘耐压站点', minWidth: 100 }
                        , { field: 'InsulatedResistanceUser', title: '绝缘耐压账号', minWidth: 100 }
                        , { field: 'EL2TimeStr', title: 'EL2时间', minWidth: 150 }
                        , { field: 'EL2Duty', title: 'EL2班次', minWidth: 100 }
                        , { field: 'EL2Machine', title: 'EL2站点', minWidth: 100 }
                        , { field: 'EL2User', title: 'EL2账号', minWidth: 100 }
                        , { field: 'NameplatePrintingTimeStr', title: '铭牌打印时间', minWidth: 150 }
                        , { field: 'NameplatePrintingDuty', title: '铭牌打印班次', minWidth: 100 }
                        , { field: 'NameplatePrintingMachine', title: '铭牌打印站点', minWidth: 100 }
                        , { field: 'NameplatePrintingUser', title: '铭牌打印账号', minWidth: 100 }
                        , { field: 'FinalInspectionTimeStr', title: '终检时间', minWidth: 150 }
                        , { field: 'FinalInspectionDuty', title: '终检班次', minWidth: 100 }
                        , { field: 'FinalInspectionMachine', title: '终检站点', minWidth: 100 }
                        , { field: 'FinalInspectionUser', title: '终检账号', minWidth: 100 }
                        , { field: 'PackTimeStr', title: '打包时间', minWidth: 150 }
                        , { field: 'PackDuty', title: '打包班次', minWidth: 100 }
                        , { field: 'PackMachine', title: '打包站点', minWidth: 100 }
                        , { field: 'PackUser', title: '打包账号', minWidth: 100 }
                        , { field: 'CellColor', title: '电池片颜色', minWidth: 100 }
                        , { field: 'ComponentColor', title: '组件颜色', minWidth: 100 }
                        , { field: 'BackPlanFactory', title: '背板厂家', minWidth: 100 }
                        , { field: 'BackPlanSpecs', title: '背板规格', minWidth: 100 }
                        , { field: 'JunBoxFactory', title: '接线盒厂家', minWidth: 100 }
                        , { field: 'JunBoxSpecs', title: '接线盒规格', minWidth: 100 }
                        , { field: 'AluFrameFactory', title: '边框厂家', minWidth: 100 }
                        , { field: 'AluFrameSpecs', title: '边框规格', minWidth: 100 }
                        , { field: 'BatteryFactory', title: '电池片厂家', minWidth: 100 }
                        , { field: 'BatterySpecs', title: '电池片规格', minWidth: 100 }
                        , { field: 'CellBoxNo', title: '电池片箱号', minWidth: 100 }
                        , { field: 'CellArea', title: '面积', minWidth: 100 }
                        , { field: 'CellEfficiency', title: '效率', minWidth: 100 }
                        , { field: 'SinglePiecePower', title: '单片功率', minWidth: 100 }
                        , { field: 'TheoreticalPower', title: '理论功率', minWidth: 100 }
                        , { field: 'ConversionEfficiency', title: '转换效率', minWidth: 100 }
                        , { field: 'EL1OncePass', title: 'EL1一次合格', minWidth: 100 }
                        , { field: 'NQCOncePass', title: 'NQC一次合格', minWidth: 100 }
                        , { field: 'EL2OncePass', title: 'EL2一次合格', minWidth: 100 }
                        , { field: 'FinalInspectionOncePass', title: '终检一次合格', minWidth: 100 }
                        , { field: 'QLevel', title: '等级', minWidth: 100 }
                        , { field: 'NameplateModel', title: '铭牌型号', minWidth: 100 }
                        , { field: 'IVPowerLevel', title: '额定功率', minWidth: 100 }
                        , { field: 'IVCurrentLevel', title: '档位', minWidth: 100 }
                        , { field: 'Isc', title: 'Isc', minWidth: 100 }
                        , { field: 'Voc', title: 'Voc', minWidth: 100 }
                        , { field: 'Vm', title: 'Vm', minWidth: 100 }
                        , { field: 'Im', title: 'Im', minWidth: 100 }
                        , { field: 'FF', title: 'FF', minWidth: 100 }
                        , { field: 'Pmax', title: 'Pmax', minWidth: 100 }
                        , { field: 'Temp', title: 'Temp', minWidth: 100 }
                        , { field: 'Ress', title: 'Ress', minWidth: 100 }
                        , { field: 'Ressh', title: 'Ressh', minWidth: 100 }
                        , { field: 'ModEff', title: 'ModEff', minWidth: 100 }
                        , { field: 'SunRef', title: 'SunRef', minWidth: 100 }
                        , { field: 'CNProduceStatus', title: '生产状态', minWidth: 100 }
                        , { field: 'PackNo', title: '打包编号', minWidth: 100 }
                        , { field: 'CabinetNo', title: '柜号', minWidth: 100 }
                        , { field: 'WarehouseName', title: '仓库', minWidth: 100 }
                        , { field: 'Location', title: '库位', minWidth: 100 }
                        , { field: 'InboundTimeStr', title: '入库时间', minWidth: 150 }
                        , { field: 'OutboundTimeStr', title: '出库时间', minWidth: 150 }
                        , { field: 'LoadTimeStr', title: '上车时间', minWidth: 150 }
                        , {
                            title: '操作', width: 120, fixed: "right", templet: function (d) {
                                var str = '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="detail(\'' + d.BarCode + '\')"><i class="layui-icon">&#xe614;</i>查看详情</button>';
                                return str;
                            }
                        }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.orderNo = $("#txtOrderNo").val().trim();
                    options.where.workOrderNo = $("#txtWorkOrderNo").val().trim();
                    options.where.cabinetNo = $("#txtCabinetNo").val().trim();
                    options.where.packNo = $("#txtPackNo").val().trim();
                    options.where.barCode = $("#txtBarCode").val().trim();
                    $("#hidBarCodes").val(options.where.barCode);
                    $("#hidPackNos").val(options.where.packNo);
                    $("#hidCabinetNos").val(options.where.cabinetNo);

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }

                $(".btnBatchSearch").click(function () {
                    var btnType = parseInt($(this).attr("btntype"));
                    var title = btnType == 0 ? "组件" : (btnType == 1 ? "打包编号" : "柜号");
                    layer.prompt({
                        formType: 2,
                        title: '请输入' + title,
                        maxlength: 100000,
                        area: ['800px', '350px'] //自定义文本域宽高
                    }, function (value, index, elem) {
                        var barCodes = value.split('\n');
                        options.where.barCode = "";
                        options.where.packNo = "";
                        options.where.cabinetNo = "";
                        if (btnType == 0) {
                            options.where.barCode = barCodes.join(',');
                        } else if (btnType == 1) {
                            options.where.packNo = barCodes.join(',');
                        } else if (btnType == 2) {
                            options.where.cabinetNo = barCodes.join(',');
                        }

                        $("#hidBarCodes").val(options.where.barCode);
                        $("#hidPackNos").val(options.where.packNo);
                        $("#hidCabinetNos").val(options.where.cabinetNo);

                        table.reload("table", options);
                        layer.close(index);
                    });
                });

                form.on('submit(submit)', function (data) {
                    var forms = data.field;
                    if (forms.workOrderNo.trim() == "" && forms.cabinetNo.trim() == "" && forms.packNo.trim() == "" && forms.barCode.trim() == "") {
                        layer.msg("请至少填写“工单号、柜号、打包编号、组件条码”中的一个或多个筛选条件，否则数据量太大无法导出", { icon: 5 });
                        return false;
                    }
                });
            });
        }

        function detail(barCode) {
            parent.layui.index.openTabsPage("/Report/ComponentDetail?barCode=" + barCode, "组件详情(" + barCode + ")");
        }
    </script>
}
